import axios from '@/utils/request'

export function getcurrUserMenus() {
  return axios({
    url: '/PermissionMenu/getCurrUserPermission',
    method: 'get'
  })
}


export async function getTreeMenus(data) {
  const res = await axios.post('/MenuManagement/getTree', data);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}
export async function create(data){
  const res=await axios.post('/MenuManagement',data);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}

export async function update(id,data){
  const res=await axios.post(`/MenuManagement/update/${id}`,data);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}
export async function deleteMenu(id){
  const res=await axios.post(`MenuManagement/Delete/${id}`);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}

export async function getById(id){
  const res = await axios.get(`MenuManagement/Get/${id}`);
  if (res.code == 1) {
    return res.data;
  } else {
    return Promise.reject(new Error(res.message));
  }
}